package com.github.kt

import java.math.RoundingMode
import java.util.Calendar


/**
 *  kotlin String 扩展
 * @author <a href="https://github.com/karai-oss">Mr.xie</a>
 * @Date 2025/5/6
 */


/**
 * 替换所有空格
 */
fun String.trimAllSpace(): String {
    return this.replace("\\s".toRegex(), "")
}


/**
 * 提取中文金额数额
 */
fun String.extractChineseMoney(): Double {
    val regex = """¥(\d+\.?\d*)""".toRegex()
    val matcher = regex.find(this)

    return matcher?.groupValues?.get(1)?.toDoubleOrNull() ?: 0.0
}


/**
 * 提取英文金额数额
 */
fun String.extractEnglishMoney(): Double {
    val regex = """\$(\d+\.?\d*)""".toRegex()
    val matcher = regex.find(this)

    return matcher?.groupValues?.get(1)?.toDoubleOrNull() ?: 0.0
}


fun String.keepDoubleBitNum(bitNum : Int ){
    this.toDouble()
        .toBigDecimal()
        .setScale(bitNum, RoundingMode.HALF_UP)
}